
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#define FUNCIONES_HASH 48

//#define LARGOPALABRA 6

#define MAXIMO 99991

#define RANDOM_INT_0 65644
#define RANDOM_INT_1 43144
#define RANDOM_INT_2 54434
#define RANDOM_INT_3 23231
#define RANDOM_INT_4 23338
#define RANDOM_INT_5 54353
#define RANDOM_INT_6 42365
#define RANDOM_INT_7 67865
#define RANDOM_INT_8 68678
#define RANDOM_INT_9 46323
#define RANDOM_INT_10 77076
#define RANDOM_INT_11 54432
#define RANDOM_INT_13 98797
#define RANDOM_INT_12 87643
#define RANDOM_INT_14 43697
#define RANDOM_INT_15 43212

#define PRIMO_0 1999
#define PRIMO_1 2047
#define PRIMO_2 4013
#define PRIMO_3 8191
#define PRIMO_4 9907
#define PRIMO_5 10667
#define PRIMO_6 11471
#define PRIMO_7 11969
#define PRIMO_8 12413
#define PRIMO_9 13487
#define PRIMO_10 14009
#define PRIMO_11 14561
#define PRIMO_12 15139
#define PRIMO_13 15971
#define PRIMO_14 16231
#define PRIMO_15 16451

using namespace std;
int hashingTermino(int numDeFunc, char palabra[], float frecuencia){
	
	int primos[48] = {12007,12011,12037,12041,12043,12049,12071,12073,12097,\
	12101,12107,12109,12113,12119,12143,12149,12157,12161,12163,12197,12203,\
	12211,12227,12239,12241,12251,12253,12263,12269,12277,12281,12289,12301,\
	12323,12329,12343,12347,12373,12377,12379,12391,12401,12409,12413,12421,12433,12437,12451};
	int numRandom[48] = {69383,40886,52777,56915,77793,78335,75386,70492,96649,\
	31421,22362,50027,18690,30059,17763,33926,70540,43426,79172,85736,95211,\
	55368,52567,46429,55782,91530,92862,35123,34067,83135,13929,99802,24022,\
	63058,63069,98167,41393,38456,75011,38042,66229,87373,84421,74919,23784,98537,15198,84324};
	
	int hash = 0;
	int LARGOPALABRA = strlen(palabra);
	
	for (int i = 0; i < LARGOPALABRA; i++) {
		hash += fmod((palabra[i]*pow(numRandom[numDeFunc],i)), primos[numDeFunc]);
	}
	
	hash = fmod(hash, MAXIMO);
	return hash;
	/*
    switch(numeroDeFuncion){
      
       case 0:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_0,i)), PRIMO_0);
	  if (hash <=0 ) {
		  cout << pow(RANDOM_INT_0,i) <<" " <<palabra[i]*pow(RANDOM_INT_0,i) <<" "<<fmod((palabra[i]*pow(RANDOM_INT_0,i)), PRIMO_0)<<" ";
		  cout <<palabra <<" "<<palabra[i]<< (int)palabra[i]<<"-"<< fmod((palabra[i]*pow(RANDOM_INT_0,i)), PRIMO_0)<<"-";
		  cout << "hash: " << hash << endl;
		  }
	}
	break;
      
      case 1:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_1,i)), PRIMO_1);
	}
	break;
    
      case 2:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_2,i)), PRIMO_2);
	}
	break;
	
      case 3:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_3,i)), PRIMO_3);
	}
	break;
	
      case 4:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_4,i)), PRIMO_4);
	}
	break;
	
      case 5:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_5,i)), PRIMO_5);
	}
	break;
	
      case 6:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_6,i)), PRIMO_6);
	}
	break;
	
      case 7:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_7,i)), PRIMO_7);
	}
	break;
	
      case 8:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_8,i)), PRIMO_8);
	}
	break;
	
      case 9:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_9,i)), PRIMO_9);
	}
	break;
	
      case 10:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_10,i)), PRIMO_10);
	}
	
      case 11:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_11,i)), PRIMO_11);
	}
	break;
	
      case 12:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_12,i)), PRIMO_12);
	}
	break;
	
      case 13:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_13,i)), PRIMO_13);
	}
	break;
	
      case 14:
	
	for(int i=0; i< LARGOPALABRA;i++){
	  hash += fmod((palabra[i]*pow(RANDOM_INT_14,i)), PRIMO_14);
	}
	break;
	
      case 15:
	
	for(int i=0; i< LARGOPALABRA;i++){ //cout <<palabra[i]<< (int)palabra[i]<<"-";
	  hash += fmod((palabra[i]*pow(RANDOM_INT_15,i)), PRIMO_15); 
	  if (hash <=0 ) {
		  cout <<palabra <<" "<<palabra[i]<< (int)palabra[i]<<"-"<< fmod((palabra[i]*pow(RANDOM_INT_15,i)), PRIMO_15)<<"-";
		  cout << "hash: " << hash << endl;
		  }	
	}
	break;
	
    }
  int aux = hash;
  hash = fmod(hash, MAXIMO);
  if (hash == 0) cout << hash << " " << aux<<endl;
  return hash;
  */
}
